package com.l024.easyandroidlib.manager;

import android.app.Activity;
import android.content.Context;
import android.view.inputmethod.InputMethodManager;

/**
 * @Author: Cat
 * @CreateTime: 2022-07-29  16:27
 * @Description: 键盘管理
 * @Version: 1.0
 */
public class KeyWordManager {

    private InputMethodManager imm;

    private static volatile KeyWordManager mInstance = null;

    private KeyWordManager() {

    }

    public static KeyWordManager getInstance() {
        if (mInstance == null) {
            synchronized (KeyWordManager.class) {
                if (mInstance == null) {
                    mInstance = new KeyWordManager();
                }
            }
        }
        return mInstance;
    }

    /**
     * 隐藏软键盘
     *
     * @param mActivity
     */
    public void hideKeyWord(Activity mActivity) {
        if (mActivity != null && !mActivity.isDestroyed()) {
            if (imm == null) {
                imm = (InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
            }
            imm.hideSoftInputFromWindow(mActivity.getWindow().getDecorView().getWindowToken(), 0);
        }
    }
}
